// Pages/third/index.js
const app = getApp();
var utl = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cstatus: '--',
    cantouch:true,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var usinfo = app.globalData.userData;
    var ulaver = utl.userlevel(usinfo.levelId);
    var rstatus = utl.userStatus(usinfo.status)
    this.setData({
      userName: usinfo.userName,
      userlever: ulaver,
      userconnect: usinfo.loginName,
      cstatus: rstatus,
    })
  },
  //查看收益
  goprofit:function(){
    wx.navigateTo({
      url: '/pages/profit/index',
    })
  },
  //联系我们
  connectus:function(){
    wx.makePhoneCall({
      phoneNumber: '400-6186787' //仅为示例，并非真实的电话号码
    })
  },
  //账单查询
  ordercheck:function(){
    const status = app.globalData.userData.status;
    if (status == '30') {//注册用户
      wx.navigateTo({
        url: '/pages/regist/userredit',
      })
    } else if (status == '60') {
      wx.navigateTo({
        url: '/pages/orderlist/index',
      })
    } else {
      var err = utl.userStatus(status);
      wx.showModal({
        title: '提示',
        content: err,
        showCancel: false,
      })
    }
  },
  //我的收款卡
  cardAction: function() {
    var tt = this.data.cantouch;
   
    if(!tt){
      return;
    }
    wx.showLoading({
      title: '请求中...',
    })
    this.setData({
      cantouch: false,
    })
    utl.serverToken('/epay_apps/user/userInfoE0100', {}, (err, res) => {
      
      if (err) {
        wx.showToast({
          title: err,
          icon: 'none',
          duration: 2000
        })
        return;
      }
      var rsp = res.response;
      var cardNm = rsp.accountNo;
      var usinfo = app.globalData.userData;
      var rstatus = usinfo.status;
      if (!cardNm) {
        if(rstatus == '10'){
          var jst = JSON.stringify(rsp);
          wx.navigateTo({
            url: '/pages/skcard/index',
          })
        }else{
          wx.showToast({
            title: utl.userStatus(rstatus),
            icon: 'none',
            duration: 2000,
          })
        }
      
      } else {
        var jst = JSON.stringify(rsp);
        wx.navigateTo({
          url: '/pages/skcard/mcard?jpram=' + jst,
          
        })
      }
      this.setData({
        cantouch:true,
      })
      wx.hideLoading();
    })

  },
  logout:function(){
    wx.reLaunch({
      url: '/pages/login/index',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  //实名认证
  registuser: function() {
    var usinfo = app.globalData.userData;
    var rstatus = usinfo.status;
    var tstatus = utl.userStatus(rstatus)
    if (rstatus == '30') {
      wx.navigateTo({
        url: '/pages/regist/userredit', 
      })
    }else{
      wx.showToast({
        title: tstatus,
        icon:'none',
        duration:2000,
      })
    }
  }
})